<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>

    import {uploadPath} from "@/config/env";
    export default {
        data() {
            return {
                obj: {},
                isIdFind: true,
                initSuccess: false,
            }
        },
        props: {
            uri: {},
            rowData: {},
        },
        computed: {
            option() {
                return {
                    // size: "small",
                    submitBtn: true,
                    emptyBtn: true,
                    submitText: '提交',
                    emptyText: "关闭",
                    column: [
                        {
                            label: '站点名称',
                            prop: 'name',
                            labelWidth: 110,
                            maxlength: 64,
                            showWordLimit: true,
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请输入 站点名称",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '站点地址',
                            prop: 'site',
                            labelWidth: 110,
                            maxlength: 256,
                            showWordLimit: true,
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请输入 站点地址",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '站点类型',
                            prop: 'type',
                            type: 'radio',
                            labelWidth: 110,
                            dicData: this.dict.get('SITE_TYPE'),
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请选择 站点类型",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '访问状态',
                            prop: 'visitState',
                            type: 'radio',
                            labelWidth: 110,
                            dicData: this.dict.get('VISIT_STATE'),
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请选择 访问状态",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '是否配置 https',
                            prop: 'ifHttps',
                            type: 'radio',
                            labelWidth: 110,
                            dicData: this.dict.get('IF_HTTPS'),
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请选择 是否配置 https",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: 'https 过期时间',
                            prop: 'httpsExpirationTime',
                            type: 'datetime',
                            labelWidth: 110,
                            format: 'YYYY-MM-DD HH:mm:ss',
                            valueFormat: 'YYYY-MM-DD HH:mm:ss',
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请选择 https 过期时间",
                                trigger: "blur"
                            }]
                        },
                        {
                            label: '备注',
                            prop: 'remarks',
                            labelWidth: 110,
                            maxlength: 256,
                            showWordLimit: true,
                            span: 20,
                            rules: [{
                                required: false,
                                message: "请输入 备注",
                                trigger: "blur"
                            }]
                        },

                    ]
                }
            }
        },
        created() {
            if (this.isIdFind) {
                this.findId(this.rowData);
            } else {
                this.obj = this.rowData;
                this.initSuccess = true;
            }
        },
        methods: {
            emptytChange() {
                this.$emit('closeDialog', false);
            },
            submit(form, done) {
                this.crud.put(this.uri.info + "/" + this.obj.id, this.obj).then((res) => {
                    if (res.data.code == 200) {
                        this.$emit('closeDialog', true);
                    }
                    done(form);
                }).catch(err => {
                    console.error(err);
                    done(form);
                })
            },
            findId(rowData) {
                if (rowData != null && rowData.id != null) {
                    this.crud.get(this.uri.info + "/" + rowData.id).then((res) => {
                         Object.assign(this.obj, res.data.data);
                         this.initSuccess = true;
                    })
                }
             }
        }
    }
</script>
